<?php
namespace App\Model\CommodityModel;
use App\Model\BaseModel\BaseCommodityModel;

class Stockinfo extends BaseCommodityModel
{
    public $table = 'stockinfo_s2b';
    CONST  DEFAULT_IS_DEFECTIVE = 0;
    
    /**
     * 获取指定供应商商品批次数据
     * @param array $supplierCode
     * @param string $wareHouseID
     */
    public function getStockBatchInfoListBySupplierCodesAndWareHouseID( array $supplierCodes, string $wareHouseID )
    {
        $alias_stock_table = $this->getTable();
        $list = $this->from($alias_stock_table." as stock")
        ->select([
            "stock.BatchID",
            "scb.SupplierCommoditySkuCode"
        ])
        ->join("suppliercommodity_s2b as scb","scb.ID","=","stock.SupplierCommodityID")
        ->where('stock.WarehouseID',$wareHouseID)
        ->whereIn('scb.SupplierCommoditySkuCode',$supplierCodes)
        ->get()
        ->toArray();
        return array_column($list,'BatchID','SupplierCommoditySkuCode');//随机抽一个批次
    }
}
